﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System.Collections.Generic;
using BrainTechLLC;
using BrainTechLLC.FilterExtensions;
using ImageAppViewModels;

namespace WpfImageDuplicates
{
    public class FileImageBlurHandler : BaseNotifyPropertyChanged
    {
        protected ImageCollectionView _collectionView;

        public FileImageBlurHandler(ImageCollectionView collectionView)
        {
            _collectionView = collectionView;            
        }

        public void CalculateBlurs()
        {
            FileImageViewModel.LazyBlur.CancelAll();
            List<FileImageViewModel> alreadyCalc = new List<FileImageViewModel>();
            List<FileImageViewModel> notCalc = new List<FileImageViewModel>();

            // first enqueue items that haven't been measured
            foreach (var thumb in _collectionView._vm) //GetAllFileImageViewModels()
            {
                if (!thumb.Blur.IsValidBlurMeasure())
                {
                    notCalc.Add(thumb);
                }
            }

            // then enqueue items that have / may need updating
            foreach (var thumb in _collectionView._vm) //GetAllFileImageViewModels()
            {
                if (thumb.Blur.IsValidBlurMeasure())
                {
                    alreadyCalc.Add(thumb);
                }
            }

            notCalc.ForEach((thumb) => FileImageViewModel.LazyBlur.LazyLoad(thumb, (t) => { }));
            alreadyCalc.ForEach((thumb) => FileImageViewModel.LazyBlur.LazyLoad(thumb, (t) => { }));
        }
    }
}
